export default {
    namespaced: true,
    state: {
        // 用户的id
        user_id: localStorage.user_id || '',
        // userInfo: {
        //     // 用户性别
        //     gender: '',
        //     // 用户年龄
        //     age: 0,
        //     // 用户手机号
        //     phone: Number,
        //     // 用户状态
        //     status: 0,
        //     // 用户头像
        //     avatar: '',
        //     // 用户邮箱
        //     email: '',
        //     // 用户昵称
        //     nickname: '',
        //     // 账号
        //     username: '',
        //     // 密码
        //     password: '',
        //     // IP属地
        //     ipAddress: ''
        // },
        // accessToken
        userInfo: JSON.parse(localStorage.user_info || JSON.stringify({
            // 用户性别
            gender: '',
            // 用户年龄
            age: 0,
            // 用户手机号
            phone: Number,
            // 用户状态
            status: 0,
            // 用户头像
            avatar: '',
            // 用户邮箱
            email: '',
            // 用户昵称
            nickname: '',
            // 账号
            username: '',
            // 密码
            password: '',
            // IP属地
            ipAddress: '',
            // 背景图
            backgroundImg: ''
        })),
        accessToken: localStorage.access_token || '',
        // refreshToken
        refreshToken: localStorage.refresh_token || '',
        // tokenType
        tokenType: localStorage.token_type || '',
    },
    actions: {

    },
    mutations: {
        SET_USER_ID: (state, user_id) => {
            if (user_id == '-1') {
                state.user_id = ''
                localStorage.removeItem("user_id");
                return
            }
            state.user_id = user_id
            localStorage.user_id = user_id;
        },
        SET_accessToken: (state, access_token) => {
            if (access_token == '-1') {
                state.access_token = ''
                localStorage.removeItem("access_token");
                return
            }
            state.access_token = access_token
            localStorage.access_token = access_token;
        },
        SET_refreshToken: (state, refresh_token) => {
            if (refresh_token == '-1') {
                state.refresh_token = ''
                localStorage.removeItem("refresh_token");
                return
            }
            state.refresh_token = refresh_token
            localStorage.refresh_token = refresh_token;
        },
        SET_tokenType: (state, token_type) => {
            if (token_type == '-1') {
                state.refresh_token = ''
                localStorage.removeItem("token_type");
                return
            }
            state.token_type = token_type
            localStorage.token_type = token_type;
        },
        UPDATE_USER_INFO: (state, userInfo) => {
            if (userInfo == {}) {
                localStorage.removeItem("user_info");
                state.userInfo = userInfo
                return
            }
            localStorage.user_info = JSON.stringify(userInfo)
            state.userInfo = userInfo
        },
        SET_USER_INFO: (state, userInfo) => {
            localStorage.user_info = JSON.stringify(userInfo)
            for (let item in userInfo) {
                state.userInfo[item] = userInfo[item]
            }

        },
    },

    getters: {}
}